package _interview75;

/**
 * 1768. 交替合并字符串
 */
public class No1768 {
    public String mergeAlternately(String word1, String word2) {
        int n1 = word1.length();
        int n2 = word2.length();
        char[] chars = new char[n1 + n2];
        int min = Math.min(n1, n2);
        for (int i = 0; i < min; i++) {
            chars[2 * i] = word1.charAt(i);
            chars[2 * i + 1] = word2.charAt(i);
        }
        System.arraycopy(n1 > n2 ? word1.toCharArray() : word2.toCharArray(), min, chars, 2 * min, Math.max(n1, n2) - min);
        return new String(chars);
    }
}
